<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <nav>
      <a href="#home">首页</a>
      <a href="#login">登录</a>
      <a href="#mine">个人中心</a>
    </nav>

    <div class="container"></div>
  </div>

  <script>
    const home = `
      <div>这是首页的布局</div>
    `
    const login = `
      <div>登录表单<input placeholder="请输入用户名" /></div>
    `
    const mine = `
      <div>个人中心<div>昵称：小明</div></div>
    `

    // 监视 hash 变化
    window.onhashchange = function() {
      let html
      switch(location.hash) {
        case '#home':
          html = home
          break
        case '#login':
          html = login
          break
        case '#mine':
          html = mine
          break
      }
      document.querySelector('.container').innerHTML = html
    }
  </script>
</body>
</html>